import os
import xml.etree.ElementTree as ET


class Demo(object):

    def set_data(self, file_in_path, file_out_path, store_id):
        tree = ET.parse(file_in_path)
        root = tree.getroot()
        for item in root.iter("FILIALE"):
            item.text = str(store_id)
        tree.write(file_out_path, encoding='UTF-8')


if __name__ == '__main__':
    demo = Demo()
    my_path = os.getcwd()
    in_dir = rf'{my_path}\dir_temp'
    out_dir = rf'{my_path}\dir_datil'

    for file in os.listdir(in_dir):
        file_in_path = in_dir+'\\'+file
        index = str.find(file, 'EXT')

        for store_id in range(1000, 1048):
            store_id = 2001 if store_id == 1000 else store_id
            file_out_name = file[0:index]+str(store_id)+"_"+file[index:]
            file_out_path = out_dir + '\\' + file_out_name

            execpt_id = [1004, 1005, 1007, 1008, 1035]
            if store_id not in execpt_id:
                demo.set_data(file_in_path, file_out_path, store_id)